package mock.bean;

import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.google.common.collect.ImmutableMap;

/**
 * 订单状态枚举（含前台状态映射{@link #frontCode}和{@link #frontName}）
 *
 * @author Zhang Xiaoye
 * @date 2018年9月10日 下午5:45:56
 */
public enum OrderStatus {

	TO_PAY(1010, "待支付", 10),
	PAIED(1020, "已支付", 1050, "待发货", 20),
	TO_CONFIRM(1030, "待确认", 1050, "待发货", null),
	CONFIRMED(1031, "已确认", 1050, "待发货", 25),
	TO_AUDIT(1040, "待审核", 1050, "待发货", null),
	TO_TAKE(1041, "待接单", 1050, "代发货", null),
	TO_PICK(1043, "待拣货", 1050, "代发货", null),
	TO_DELIVERY(1050, "待配送", null),
	DELIVERED(1060, "配送中", 1060, "待收货", 30),
	SIGNED(1070, "已签收", 1070, "待评价", 40),
	COMPLETED(1999, "已完成", 50),
	//CANCEL  4000 状态值 去除
	//CANCEL(4000, "已取消", 4000, null, null),
	CLOSED(9000, "已关闭", 9000, "已取消", 60),

	CLOSED_V1(1, "已关闭", 1, "已取消", 80),

	;

	/** 编码 */
	public final Integer code;
	/** 名称 */
	public final String name;
	/** 前台编码 */
	public final Integer frontCode;
	/** 前台名称 */
	public final String frontName;
	/** 对应操作枚举 */
	public final Integer operate;

	/** 从code到枚举对象的映射（不可变）*/
	private static final Map<Integer, OrderStatus> MAP = ImmutableMap.copyOf(
			Stream.of(OrderStatus.values()).collect(Collectors.toMap(OrderStatus::getCode, Function.identity())));

	/** 从code获取枚举对象*/
	public static OrderStatus of(Integer orderStatus) {
		return orderStatus != null? MAP.get(orderStatus): null;
	}

	private OrderStatus(Integer code, String name, Integer frontCode, String frontName, Integer operate) {
		this.code = code;
		this.name = name;
		this.frontCode = frontCode;
		this.frontName = frontName;
		this.operate = operate;
	}

	private OrderStatus(Integer code, String name, Integer operate) {
		this(code, name, code, name, operate);
	}

	public Integer getCode() {
		return code;
	}

	public String getName() {
		return name;
	}

	public Integer getFrontCode() {
		return frontCode;
	}

	public String getFrontName() {
		return frontName;
	}

}
